#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int minimumLengthEncoding(vector<string>& words) {
    if (words.size() == 1) return words[0].length() + 1;
    sort(words.begin(), words.end(),
         [](string& w1, string& w2) { return w1.length() > w2.length(); });
    string tokens[2005];
    int cur = 0;
    tokens[cur++] = words[0];
    for (int i = 1; i < words.size(); i++) {
        bool isSub = 0;
        for (int j = 0; j < cur; j++) {
            // if (tokens[j].substr(tokens[j].length() - words[i].length(),
            //                      words[i].length()) == words[i]) {
            if( tokens[j].find(words[i],tokens[j].length() - words[i].length()) != string::npos){
                isSub = 1;
                break;
            }
        }
        if (!isSub) tokens[cur++] = words[i];
    }
    int ans = 0;
    for (int i = 0; i < cur; i++) {
        ans += tokens[i].length() + 1;
    }
    return ans; 
}

int main() {
    vector<string> words = {"me", "time"};
    int ans = minimumLengthEncoding(words);
    cout << ans << endl;
    return 0;
}